var pageNo = 1;

$(function(){
	/* 默认加载可用  */
	loadCouponAlive();
	
	/*加载已使用的优惠券*/
	loadCouponUsed();
	
	/*加载已过期的优惠券*/
	loadCouponTimeOver();
});

//加载可以使用的优惠券
function loadCouponAlive(){
	$.ajax({
		url:g_requestContextPath + "/user/getCoupon",
		type:"post",
		dataType:"json",
		data:{"status":"N"},
		async:false, 
		success:function(data){
//			console.log(data);
			var couponHtml = '';
			for (var i = 0; i < data.length; i++) {
				couponHtml += '<li class="addrate">';
				couponHtml += '<p class="stress">'+data[i].title+'</p>';
				couponHtml += '<p class="stress abs"><span>￥</span>'+parseInt(data[i].value) / 100+'</p>';
				couponHtml += '<p class="coupon-meta"><span>适用范围：</span> <span class="stress">'+data[i].productUseType+''+data[i].conditionDay+'及以上标 </span> </p>';
				couponHtml += '<p class="coupon-meta"><span>使用条件：</span><span class="stress">投资满'+thousandBitSeparator(parseInt(data[i].conditionMoney)/100)+'元可用</span></p>';
				couponHtml += '<p class="coupon-meta u-tim"><span>过期日期</span><span class="stress">'+data[i].endTime.substring(0,19)+'</span> <i class="coupon-count">'+data[i].count+'</i> </p>';
				couponHtml += '</li>';
			}
			$("#avail_coupon_alive").html(couponHtml);
			
		}
	});
}

//已用优惠券
function loadCouponUsed(){
	var couponHtml = '';
	$.ajax({
		url:g_requestContextPath + "/user/getCoupon",
		type:"post",
		dataType:"json",
		data:{"status":"Y"},
		async:false, 
		success:function(data){
			for (var i = 0; i < data.length; i++) {
				couponHtml += '<li class="status1">';
				couponHtml += '<p class="stress">'+data[i].title+'</p>';
				couponHtml += '<p class="stress gray"><span>￥</span>'+parseInt(data[i].value) / 100+'</p>';
				couponHtml += '<p class="coupon-meta"><span>适用范围：</span> <span class="stress">'+data[i].productUseType+''+data[i].conditionDay+'及以上标 </span> </p>';
				couponHtml += '<p class="coupon-meta"><span>使用条件：</span><span class="stress">投资满'+thousandBitSeparator(parseInt(data[i].conditionMoney)/100)+'元可用</span></p>';
				couponHtml += '<p class="coupon-meta u-tim"><span>过期日期</span><span class="stress">'+data[i].endTime.substring(0,19)+'</span> <i class="coupon-count">'+data[i].count+'</i> </p>';
				couponHtml += '</li>';
			}
			$("#avail_coupon").html(couponHtml);
		}
	});
}

//加载已过期的优惠券
function loadCouponTimeOver(){
	var couponHtml = '';
	$.ajax({
		url:g_requestContextPath + "/user/getCoupon",
		type:"post",
		dataType:"json",
		data:{"status":"O"},
		async:false, 
		success:function(data){
			for (var i = 0; i < data.length; i++) {
				couponHtml += '<li class="status2">';
				couponHtml += '<p class="stress">'+data[i].title+'</p>';
				couponHtml += '<p class="stress gray"><span>￥</span>'+parseInt(data[i].value) / 100+'</p>';
				couponHtml += '<p class="coupon-meta"><span>适用范围：</span> <span class="stress">'+data[i].productUseType+''+data[i].conditionDay+'及以上标 </span> </p>';
				couponHtml += '<p class="coupon-meta"><span>使用条件：</span><span class="stress">投资满'+thousandBitSeparator(parseInt(data[i].conditionMoney)/100)+'元可用</span></p>';
				couponHtml += '<p class="coupon-meta u-tim"><span>过期日期</span><span class="stress">'+data[i].endTime.substring(0,19)+'</span> <i class="coupon-count">'+data[i].count+'</i> </p>';
				couponHtml += '</li>';
			}
			$("#avail_coupon").append(couponHtml);
		}
	});
}
